package exam.demo18;

public class Test1 {
    public static String compressString (String param) {
        // write code here
        StringBuffer str = new StringBuffer();
        int len = param.length();
        int i = 0;
        int j = 0;
        int count = 0;
        while (i < len || j < len) {
            char a = param.charAt(i);
            char b = param.charAt(j);
            str.append(a);
            while (j < len && param.charAt(i) == param.charAt(j)) {
                j++;
                count++;
            }
            if (count > 1) {
                str.append(count);
            }
            count = 0;
            i = j;
        }

        return str.toString();
    }

    public static void main(String[] args) {
        System.out.println(compressString("aabcccccaaa"));
    }
}
